package com.ygy.jxc.service.Impl;

import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.ygy.jxc.dao.JcCustomerDao;
import com.ygy.jxc.dao.JcShopDao;
import com.ygy.jxc.dto.shopTypeDto;
import com.ygy.jxc.mapper.JcmdCustomerMapper;
import com.ygy.jxc.mapper.JcmdShopMapper;
import com.ygy.jxc.mapper.JcmdShopTypeMapper;
import com.ygy.jxc.model.*;
import com.ygy.jxc.service.JcCustomerService;
import com.ygy.jxc.service.JcShopService;
import com.ygy.jxc.util.dateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 部门  service
 */
@Service
public class JcShopServiceImpl implements JcShopService {

    @Autowired
    private JcmdShopMapper shopMapper;

    @Autowired
    private JcmdShopTypeMapper shopTypeMapper;
    @Autowired
    private JcShopDao shopDao;


    @Override
    public int create(JcmdShop shop) {

        shop.setBuildDate(LocalDateTime.now());
        // dept.setAdminCount(0);
        //  role.setSort(0);
        return shopMapper.insert(shop);
    }

    @Override
    public int update(JcmdShop shop) {
        shop.setUpdateDate(LocalDateTime.now());
        //updateByPrimaryKeySelective 传入字段为null不更新数据库字段
        return shopMapper.updateByPrimaryKeySelective(shop);
    }

    @Override
    public int updateOrAddById(JcmdShop shop) {
        if (shop.getId() != null && shop.getId() != 0) {//更新
            this.update(shop);
        } else {
            this.create(shop);
        }
        //先默认删除/修改 成功
        return 1;
    }

    @Override
    public int delete(Long id) {
        int count = shopMapper.deleteByPrimaryKey(id);
        //  adminCacheService.delResourceListByRoleIds(ids);
        return count;
    }

    @Override
    public List<JcmdShop> list() {
        return null;
    }

/*
    @Override
    public List<JcmdShop> list() {
        return shopMapper.selectByExample(new JcmdShopExample());
    }
*/

    @Override
    public List<JcmdShop> list(String keyword, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        JcmdShopExample example = new JcmdShopExample();
        if (!StrUtil.isEmpty(keyword)) {
            example.createCriteria().andNameLike("%" + keyword + "%");
        }
        return shopMapper.selectByExample(example);
    }

    @Override
    public JcmdShopType selectShopTypeByName(String shopName) {

        return shopDao.selectShopTypeByName(shopName);

    }

    @Override
    public ArrayList<Object> getShopNameAll() {
        List<JcmdShop> jcmdShops = shopMapper.selectByExample(new JcmdShopExample());
        // Map<Long,String> map = new HashMap<>();
        ArrayList<Object> shopNameList = new ArrayList<>();
        if (jcmdShops != null && jcmdShops.size() > 0) {
            for (JcmdShop shop : jcmdShops) {
                Map<String, Object> map = new HashMap<>();
                //   System.out.println("id "+shop.getId()+"\t name " +shop.getName());
                map.put("id", shop.getId());
                map.put("name", shop.getName());
                shopNameList.add(map);
            }
        }
        return shopNameList;
    }


    /**
     *  获取商品类型的
     * @return
     */
    @Override
    public List<JcmdShopType> selectShopTypeList() {
        return  shopTypeMapper.selectByExample(new JcmdShopTypeExample());
    }
}
    /**
     * 【商品类型   采购量   销售量   库存量】
     */
//    @Override
//    public shopTypeDto selectShopTypeList() {
//        List<JcmdShopType> shopTypeList = shopTypeMapper.selectByExample(new JcmdShopTypeExample());
//        /**
//         * 1. 获取商品类型
//         * 2. 通过商
